home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / cli / CD32goodies.lha / cdmotor.c < prev    next >
C/C++ Source or Header  |  1995-04-19  |  2KB  |  79 lines

  1. /*
  2.     CD Stopper Daemon for the CD³² Multimedia Computer
  3.  
  4.     ( Original Idea found on Aminet-5 CD, its called
  5.       aminet5:aminet/wb/util/cd_stop.lha )
  6.  
  7.     this has nothing to do with the similar program
  8.     named above - you should use your favorite; note
  9.     that the other one is much shorter but has not
  10.     the ability of being a daemon.
  11.     
  12.  
  13.     written by Daniel Balster, dbalster@uni-paderborn.de
  14. */
  15.  
  16. #include <exec/exec.h>
  17. #include <dos/dos.h>
  18. #include <devices/cd.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #define DEFAULT_DELAY    500    /* ticks */
  23.  
  24. struct {
  25.     ULONG    interval;
  26.     BOOL    quiet;
  27.     ULONG    pads[14];
  28. } args = {0};
  29.  
  30. int main (void)
  31. {
  32.     struct RDArgs *rdargs;
  33.     struct MsgPort *mp;
  34.     struct IOStdReq *ior;
  35.     
  36.     BOOL quit = FALSE;
  37.  
  38.     if (rdargs=ReadArgs("DELAY/N,QUIET/S",(LONG*)&(args),NULL))
  39.     {
  40.         if(!args.quiet) PutStr("*** CD Stopper *** for the Amiga CD³²® Computer\nwritten by Daniel Balster\n");
  41.  
  42.         if(mp=CreateMsgPort())
  43.         {
  44.             if(ior=(struct IOStdReq*)CreateIORequest(mp,sizeof(struct IOStdReq)))
  45.             {
  46.                 if(!OpenDevice("cd.device",0,ior,0))
  47.                 {
  48.                     while (!quit)
  49.                     {
  50.                         if(!args.quiet) PutStr("stopping motor!\n");
  51.                         ior->io_Command    = CD_MOTOR;
  52.                         ior->io_Length    = 0;        /* motor off */
  53.                         DoIO(ior);
  54.             
  55.                         Delay (*(ULONG*)args.interval);
  56.             
  57.                         if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) quit=TRUE;
  58.                     
  59.                     }
  60.                     PutStr("*** BREAK!\n");
  61.                 
  62.                     CloseDevice((struct IORequest*)ior);
  63.                 }
  64.                 else PutStr("cannot access cd.device?\n");
  65.                 
  66.                 DeleteIORequest((struct IORequest*)ior);
  67.             }
  68.             else PutStr("cannot create ioreq?\n");
  69.  
  70.             DeleteMsgPort(mp);
  71.         }
  72.         else PutStr("cannot create msgport?\n");
  73.  
  74.         FreeArgs(rdargs);
  75.     }
  76.     else PrintFault(IoErr(),0);
  77.  
  78.     return RETURN_OK;
  79. }